Skip to content

Token: do not return non-const pointer from const methods - part 1#4761

Merged
danmar merged 8 commits intocppcheck-opensource:mainfrom
firewave:token-safe
Feb 8, 2023
Merged

Token: do not return non-const pointer from const methods - part 1#4761
danmar merged 8 commits intocppcheck-opensource:mainfrom
firewave:token-safe

Conversation

@firewave
Copy link
Copy Markdown
Collaborator

@firewave firewave commented Feb 1, 2023

Split from #4760.

@firewave firewave marked this pull request as draft February 2, 2023 01:29
@firewave firewave changed the title some Token constness adjustments Token: do not hand out non-const pointer from const methods - part 1 Feb 2, 2023
@firewave firewave changed the title Token: do not hand out non-const pointer from const methods - part 1 Token: do not return non-const pointer from const methods - part 1 Feb 2, 2023
@firewave firewave marked this pull request as ready for review February 2, 2023 20:32
Comment thread lib/valueflow.cpp
else if (tok->variable() && tok->variable()->isArray() && tok->variable()->isConst() &&
tok->variable()->nameToken() == tok && Token::Match(tok, "%var% [ %num%| ] = {")) {
const Token* rhstok = tok->next()->link()->tokAt(2);
Token* rhstok = tok->next()->link()->tokAt(2);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these can stay const.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are all based straight on compiler errors when the signature has been fixed - so no, they cannot.

Also from looking at the code it is used to get a new value for tok two lines down and that is not const.

Comment thread lib/templatesimplifier.cpp Outdated
Comment thread lib/templatesimplifier.cpp
@danmar danmar merged commit f7a415d into cppcheck-opensource:main Feb 8, 2023
@danmar
Copy link
Copy Markdown
Collaborator

danmar commented Feb 8, 2023

Nice work!

@firewave
Copy link
Copy Markdown
Collaborator Author

firewave commented Feb 8, 2023

Nice work!

Not done yet . The messy part is still coming up...

And it would be actually nice if the things you found in the review (well spotted BTW) could be found by tooling.

@firewave firewave deleted the token-safe branch February 8, 2023 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants